/*
Arm Tracker and Glove Demo by Noah Zerkin (noazark AT gmail.com) 2009
Released under GNU GPLv3.0 http://www.opensource.org/licenses/gpl-3.0.html
*/

void camControl(){
  if (!pov){
    if (!buttonC){
      if (abs(joyX) >= 10){
        camHoriz += (0.01*(float)joyX);
      }
      if (abs(joyY) >= 10){
        camVert += (0.01*(float)joyY);
      }
    }
    if (buttonC){
      if (abs(joyY) >= 10){
        zoom += -.2*((float)joyY);
      }
    }
  }
  if (pov){
    //vr920roll  = vr920.GetRoll();
   /* 
   vr920pitch = 180*vr920.GetPitch();
    vr920yaw   = 180*vr920.GetHeading();
    */
    //  if(vr920pitch>=0){
    //    vr920yaw+=.5*vr920pitch;
    //  }
    //    print(vr920pitch);print("-");println(vr920yaw);
    pushMatrix();
    translate(eyeX, eyeY, eyeZ);
    //    pushMatrix();    
    rotateY(radians(vr920yaw));
    //      pushMatrix();
    rotateZ(radians(vr920pitch));
    camX = int(modelX(4000,0,0));
    camY = int(modelY(4000,0,0));
    camZ = int(modelZ(4000,0,0));
    hudX = int(modelX(400,0,0));
    hudY = int(modelY(400,0,0));
    hudZ = int(modelZ(400,0,0));
    //      popMatrix();
    popMatrix();
    pushMatrix();
    translate(camX, camY, camZ);
    if (reticle){
      sphere(5);
    }
    popMatrix();
        camHoriz = vr920yaw;
        camVert = vr920pitch;
        zoom = 200;
  }
  if(!pov){
    camDist = cos(radians(abs(camVert)))*zoom;
    camY = (int)(sin(radians(camVert))*zoom);
    camX = (int)(cos(radians(camHoriz))*camDist);
    camZ = (int)(sin(radians(camHoriz))*camDist);
  }
}
